#!/usr/bin/env python
import pika
import sys

exchange = "111111111-single"

connection = pika.BlockingConnection(pika.ConnectionParameters(
    host='ek.hongen.com',
    credentials=pika.credentials.PlainCredentials(username="hongen", password="hongen"), ))
channel = connection.channel()

channel.exchange_declare(exchange=exchange,
                         exchange_type='direct')

message = ' '.join(sys.argv[2:]) or 'Hello World!'
routing_key = sys.argv[1] if len(sys.argv) > 1 and sys.argv[1] != '_' else ''
channel.basic_publish(exchange=exchange,
                      routing_key=routing_key,
                      body=message)
print(" [x] Sent %r, routing_key: %s" % (message, routing_key))
connection.close()
